package com.ruoyi.web.controller.box;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.TBoxInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TDeviceInfo;
import com.ruoyi.system.service.ITDeviceInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备数据Controller
 * 
 * @author ruoyi
 * @date 2024-12-20
 */
@RestController
@RequestMapping("/system/device")
public class TDeviceInfoController extends BaseController
{
    @Autowired
    private ITDeviceInfoService tDeviceInfoService;

    /**
     * 查询设备数据列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TDeviceInfo tDeviceInfo)
    {
        startPage();
        List<TDeviceInfo> list = tDeviceInfoService.selectTDeviceInfoList(tDeviceInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备数据列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDeviceInfo tDeviceInfo)
    {
        List<TDeviceInfo> list = tDeviceInfoService.selectTDeviceInfoList(tDeviceInfo);
        ExcelUtil<TDeviceInfo> util = new ExcelUtil<TDeviceInfo>(TDeviceInfo.class);
        util.exportExcel(response, list, "设备数据数据");
    }

    /**
     * 获取设备数据详细信息
     */
    @GetMapping(value = "/{deviceCode}")
    public AjaxResult getInfo(@PathVariable("deviceCode") String deviceCode)
    {
        return success(tDeviceInfoService.selectTDeviceInfoByDeviceCode(deviceCode));
    }

    /**
     * 新增设备数据
     */
    @PostMapping
    public AjaxResult add(@RequestBody TDeviceInfo tDeviceInfo)
    {
        return toAjax(tDeviceInfoService.insertTDeviceInfo(tDeviceInfo));
    }

    /**
     * 修改设备数据
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TDeviceInfo tDeviceInfo)
    {
        return toAjax(tDeviceInfoService.updateTDeviceInfo(tDeviceInfo));
    }

    /**
     * 删除设备数据
     */
	@DeleteMapping("/{deviceCodes}")
    public AjaxResult remove(@PathVariable String[] deviceCodes)
    {
        return toAjax(tDeviceInfoService.deleteTDeviceInfoByDeviceCodes(deviceCodes));
    }

    /**
     * 设备批量出库
     * @param deviceCodes
     * @param tDeviceInfo
     * @return
     */
    @PostMapping ("ckDevice/{deviceCodes}")
    public AjaxResult ckDevice(@PathVariable("deviceCodes") String[] deviceCodes,@RequestBody TDeviceInfo tDeviceInfo)

    {
        if (StringUtils.isBlank(tDeviceInfo.getCustomerInfo())){
            tDeviceInfo.setCustomerInfo("");
        }
        if (StringUtils.isBlank(tDeviceInfo.getCustomerRemark())){
            tDeviceInfo.setCustomerRemark("");
        }
        return toAjax(tDeviceInfoService.ckDeviceInfoByDeviceCodes(tDeviceInfo,deviceCodes));
    }
}
